package com.itgo.codegen.config;

import org.apache.commons.lang.StringUtils;

import com.itgo.codegen.gen.actiongen.TemplateParam;


public class Config {
	
	public static String driverPath = "com.mysql.jdbc.Driver";
	
	//数据库配置
	public static String dbUserName ="root";
	public static String dbPassword = "123456";
	public static String dbName = "idc30" ;
	public static String jdbcUrl = "jdbc:mysql://172.31.24.91:3306/"+dbName+"?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=true" ;
	
	
	//表类配置
	public static String tableName = "tb_system_message" ;
	public static String tableAliasName = "SystemMessageVO" ;
	public static String entityName = "SystemMessageVO" ;
	public static String entityPackage = "com.lain.test" ;

	//保存位置、模板配置
	public static String targetBeanPath = "C:/workspace/data/codegen/" ;
	public static String targetMapperPath = "C:/workspace/data/codegen/" ;
	public static String targetPath = "C:/workspace/data/codegen/" ;
	public static String templateBeanName = "bean.java" ;
	public static String templateMapperName = "mapper.xml" ;
	
	//模板参数
	public static TemplateParam templateParam ;
	
	public static enum TypeEnum{
		
		VARCHAR("VARCHAR" , "String" , "VARCHAR"),
		INTEGER("INTEGER" , "Integer" , "INT"),
		DATE("VARCHAR" , "String" , "DATE"),
		TIMESTAMP("VARCHAR" , "String" , "TIMESTAMP"),
		DATATIME("VARCHAR" , "String" , "DATETIME") ,
		UNSINT("INTEGER" , "Integer" , "INT UNSIGNED") ,
		UNSTINYINT("INTEGER" , "Integer" , "TINYINT UNSIGNED") ,
		UNSSMALL("INTEGER" , "Integer" , "SMALLINT UNSIGNED") ,
		TINYINT("TINYINT" , "Integer" , "TINYINT"),
		SMALLINT("SMALLINT" , "Integer" , "SMALLINT"),
		BIGINT("BIGINT" , "Long" , "BIGINT"),
		FLOAT("FLOAT" , "Float" , "FLOAT"),
		DOUBLE("DOUBLE" , "Double" , "DOUBLE"),
		NUMERIC("NUMERIC" , "BigDecimal" , "NUMERIC"),
		DECIMAL("DECIMAL" , "BigDecimal" , "DECIMAL"),
		BIT("BIT" , "Integer" , "BIT"),
		CHAR("CHAR" , "String" , "CHAR"),
		TEXT("VARCHAR" , "String" , "TEXT") ,
		REAL("REAL" , "Float" , "FLOAT"),
		BOOLEAN("BOOLEAN" , "Boolean" , "BOOLEAN"),
		BINARY("BINARY" , "Byte[]" , "BINARY"),
		VARBINARY("VARBINARY" , "Byte[]" , "BINARY"),
		LONGVARBINARY("LONGVARBINARY" , "Byte[]" , "BINARY"),
		TIME("VARCHAR" , "String" , "TIME"),
		ENUM("VARCHAR" , "String" , "ENUM"),
		BLOB("BLOB" , "String" , "BLOB") ,
		MEDIUMINT("MEDIUMINT" ,"Integer" , "MEDIUMINT");
		
		private String jdbcType ;
		private String javaType ;
		private String dbType ;
		TypeEnum( String jdbcType , String javaType , String dbType ){
			this.jdbcType = jdbcType ;
			this.javaType = javaType ;
			this.dbType = dbType ;
		}
		
		public static TypeEnum byDBType( String dbType ){
			if( StringUtils.isEmpty( dbType ) ){
				return null ;
			}
			TypeEnum[] types = TypeEnum.values() ;
			for( TypeEnum type : types ){
				if( dbType.equalsIgnoreCase( type.dbType ) ){
					return type ;
				}
			}
			return null ;
		}
		public String getJdbcType() {
			return jdbcType;
		}
		public String getJavaType() {
			return javaType;
		}
		public String getDbType() {
			return dbType;
		}
	}
	
	public static String getTargetBeanName(){
		return entityName+".java" ;
	}
	
	public static String getTargetMapperName(){
		return entityName+"Mapper.xml" ;
	}
	
	public static void configTable(
			String tableName , String aliasName , String entityName ){
		Config.tableName = tableName ;
		Config.tableAliasName = aliasName ;
		Config.entityName = entityName ;
	}
	
}
